package com.ruoyi.web.controller.leave;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.leave.domain.LeaveInfo;
import com.ruoyi.leave.service.ILeaveInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出行信息Controller
 *
 * @author rockvan
 * @date 2023-04-10
 */
@Api("出行信息管理")
@RestController
@RequestMapping("/leave/leaveinfo")
public class LeaveInfoController extends BaseController
{
    @Autowired
    private ILeaveInfoService leaveInfoService;

    /**
     * 查询出行信息列表
     */
    @ApiOperation("查询出行信息列表")
    @PreAuthorize("@ss.hasPermi('leave:leaveinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaveInfo leaveInfo)
    {
        startPage();
        List<LeaveInfo> list = leaveInfoService.selectLeaveInfoList(leaveInfo);
        return getDataTable(list);
    }

    /**
     * 导出出行信息列表
     */
    @ApiOperation("导出出行信息列表")
    @PreAuthorize("@ss.hasPermi('leave:leaveinfo:export')")
    @Log(title = "出行信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeaveInfo leaveInfo)
    {
        List<LeaveInfo> list = leaveInfoService.selectLeaveInfoList(leaveInfo);
        ExcelUtil<LeaveInfo> util = new ExcelUtil<LeaveInfo>(LeaveInfo.class);
        util.exportExcel(response, list, "出行信息数据");
    }

    /**
     * 获取出行信息详细信息
     */
    @ApiOperation("获取出行信息详细信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('leave:leaveinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(leaveInfoService.selectLeaveInfoById(id));
    }

    /**
     * 新增出行信息
     */
    @ApiOperation("新增出行信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "编号", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "username", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "dormitory", value = "门牌号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "phoneNumber", value = "手机号码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "reason", value = "出行原因", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "traffic", value = "出行方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "address", value = "目的地", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "line", value = "行程路线", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('leave:leaveinfo:add')")
    @Log(title = "出行信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaveInfo leaveInfo)
    {
        leaveInfo.setUsername(getUsername());
        return toAjax(leaveInfoService.insertLeaveInfo(leaveInfo));
    }

    /**
     * 修改出行信息
     */
    @ApiOperation("修改出行信息")
    @PreAuthorize("@ss.hasPermi('leave:leaveinfo:edit')")
    @Log(title = "出行信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaveInfo leaveInfo)
    {
        return toAjax(leaveInfoService.updateLeaveInfo(leaveInfo));
    }

    /**
     * 删除出行信息
     */
    @ApiOperation("删除出行信息")
    @ApiImplicitParam(name = "ids", value = "编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('leave:leaveinfo:remove')")
    @Log(title = "出行信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(leaveInfoService.deleteLeaveInfoByIds(ids));
    }
}
